<?php
/**
 *                    _ooOoo_
 *                   o8888888o
 *                   88" . "88
 *                   (| -_- |)
 *                    O\ = /O
 *                ____/`---'\____
 *              .   ' \\| |// `.
 *               / \\||| : |||// \
 *             / _||||| -:- |||||- \
 *               | | \\\ - /// | |
 *             | \_| ''\---/'' | |
 *              \ .-\__ `-` ___/-. /
 *           ___`. .' /--.--\ `. . __
 *        ."" '< `.___\_<|>_/___.' >'"".
 *       | | : `- \`.;`\ _ /`;.`/ - ` : | |
 *         \ \ `-. \_ __\ /__ _/ .-` / /
 * ======`-.____`-.___\_____/___.-`____.-'======
 *                    `=---='
 *
 * .............................................
 *          佛祖保佑             永无BUG
 */

namespace App\Admin\Extensions;


use Encore\Admin\Admin;

class PeopleWithdraw
{
    protected $message;

    public function __construct(array $message)
    {
        $this->message = $message;
    }

    protected function script()
    {
        return <<<SCRIPT

$('.{$this->message['btn_listen']}').on('click', function () {

    // Your code.
    var url= $(this).data('url');
    
    swal({ 
  title: "{$this->message['title']}", 
  text: "{$this->message['desc']}", 
  type: "info", 
  showCancelButton: true, 
  closeOnConfirm: false, 
  showLoaderOnConfirm: true, 
},
function(){ 
$.get(url,{},function(data){
                if(data.code=='error'){   
                    
                    swal("操作失败", data.message,"error")
                    
                }else{
                    swal("操作成功", data.message,"success")
                     $.pjax.reload('#pjax-container');
                }
            });

});    
});

SCRIPT;
    }
    protected function render()
    {

        Admin::script($this->script());

        return "<a style='float:left;margin-left:10px;' class='btn btn-xs {$this->message['btn_class']} {$this->message['btn_listen']}' data-url='{$this->message['url']}'>{$this->message['btn_name']}</a>";
    }

    public function __toString()
    {
        return $this->render();
    }

}